package api

import (
	"RESTfulAPI/basic/config"
	__ "RESTfulAPI/basic/proto"
	"RESTfulAPI/handler/request"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func Login(c *gin.Context) {
	var req request.LoginReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "数据绑定失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.UserClient.Login(c, &__.LoginReq{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
		"data": r,
	})
}
